package cn.gd.controller.IncomeProofApplicationsController;


import cn.gd.pojo.Incomeproofapplications;
import cn.gd.pojo.Users;
import cn.gd.service.IncomeProofApplicationsService.IncomeProofApplicationsService;
import cn.gd.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/income - proof - applications")
public class IncomeProofApplicationsController {

    @Autowired
    private IncomeProofApplicationsService incomeProofApplicationsService;



    // 获取所有收入证明申请
    @GetMapping("/findAll")
    public Result<List<Incomeproofapplications>> findAll() {
        List<Incomeproofapplications> list = incomeProofApplicationsService.findAll();
        return Result.ok(list);
    }

    // 根据ID获取收入证明申请
    @GetMapping("/findById/{ProofID}")
    public Result<Incomeproofapplications> findById(@PathVariable Integer ProofID) {
        Incomeproofapplications application = incomeProofApplicationsService.findById(ProofID);
        if (application!= null) {
            return Result.ok(application);
        }
        return Result.error();
    }

    // 新增收入证明申请
    @PostMapping("/save")
    public Result<Incomeproofapplications> save(@RequestBody Incomeproofapplications incomeProofApplications) {
        Incomeproofapplications saved = incomeProofApplicationsService.save(incomeProofApplications);
        return Result.ok(saved);
    }

    // 更新收入证明申请
    @PutMapping("/update/{ProofID}")
    public Result<Incomeproofapplications> update(@PathVariable Integer ProofID, @RequestBody Incomeproofapplications incomeProofApplications) {
        incomeProofApplications.setProofID(ProofID);
        Incomeproofapplications updated = incomeProofApplicationsService.update(incomeProofApplications);
        if (updated!= null) {
            return Result.ok(updated);
        }
        return Result.error();
    }

    // 删除收入证明申请
    @DeleteMapping("/deleteById/{ProofID}")
    public Result<Void> deleteById(@PathVariable Integer ProofID) {
        incomeProofApplicationsService.deleteById(ProofID);
        return Result.error();
    }


}
